package heapSort;

import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description: 测试堆排序
 * User: 86187
 * Date: 2022-08-11
 * Time: 14:17
 */

public class TestHeapSort {
    //测试堆排序所用时间
    public static void testHeapSort(int[] array) {
          array = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        MyHeapSort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时:"+(endTime - startTime)+"ms");
        //System.out.println(Arrays.toString(array));

    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        //initArrayOrder(array); //有序初始化
        initArrayNotOrder(array); //无序初始化

        testHeapSort(array);
        //System.out.println(Arrays.toString(array));
    }

    public static void initArrayOrder(int[] array) {
        //有序的初始化
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    public static void initArrayNotOrder(int[] array) {
        //不有序的初始化
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }


}
